import { get, to } from "~/utils/wxapi";
Page({
  data: {
    ceil: [
      {
        src: "../../image/name.png",
        title: "个人中心",
        url: "/pages/myinfo/myinfo",
      },
      {
        src: "../../image/order.png",
        title: "订单中心",
        url: "/pages/order/order",
      },
      {
        src: "../../image/name.png",
        title: "管理员管理",
        url: "/pages/admin/admin",
        id: "1",
      },
      { src: "../../image/logout.png", title: "退出登录" },
    ],
    user: {},
  },
  onShow() {
    if (typeof this.getTabBar === "function" && this.getTabBar()) {
      this.getTabBar().setData({
        selected: 3,
      });
    }
    const user = get("user");
    if (user) {
      this.setData({ user });
    } else {
      to("/pages/login/login");
    }
  },
  goto(e: any) {
    const { url } = e.currentTarget.dataset;
    if (url) {
      to(url);
    } else {
      wx.removeStorageSync("user");
      this.onShow();
    }
  },
});
